package net.fdukedom.epicurus.domain.entity;

import java.util.Date;

/**
 * Log entry class.
 *
 * @author Sergey Vishnyakov
 */
public final class LogEntry {

    /**
     * Id.
     */
    private int id;
        
    /**
     * Writer's id.
     */
    private String writerId;
    
    /**
     * Log message.
     */
    private String message;
    
    /**
     * Log status.
     */
    private String status;
    
    /**
     * User's registration date.
     */
    private Date time = new Date();

    /**
     * Default constructor.
     */
    public LogEntry() {
    }

    /**
     * Creates log entry out of all required info.
     *
     * @param message message to be logged
     * @param writerId writerId
     * @param status event status
     */
    public LogEntry(String message, String writerId, String status) {
        this.writerId = writerId;
        this.message = message;
        this.status = status;
    }

    /**
     * Returns entry id.
     *
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * Sets entry id.
     *
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * Returns message.
     *
     * @return the message
     */
    public String getMessage() {
        return message;
    }

    /**
     * Sets message.
     *
     * @param message the message to set
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * Returns status.
     *
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * Sets status.
     *
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * Returns creation date.
     *
     * @return the time
     */
    public Date getTime() {
        return time;
    }

    /**
     * Sets creation date.
     *
     * @param time the time to set
     */
    public void setTime(Date time) {
        this.time = time;
    }

    /**
     * Returns writerId.
     *
     * @return the writerId
     */
    public String getWriterId() {
        return writerId;
    }

    /**
     * Sets writerId.
     *
     * @param writerId the writerId to set
     */
    public void setWriterId(String writerId) {
        this.writerId = writerId;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final LogEntry logEntry = (LogEntry) o;

        if (id != logEntry.id) return false;
        if (!writerId.equals(logEntry.writerId)) return false;
        if (!message.equals(logEntry.message)) return false;
        if (!status.equals(logEntry.status)) return false;
        if (!time.equals(logEntry.time)) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = id;
        result = 29 * result + writerId.hashCode();
        result = 29 * result + message.hashCode();
        result = 29 * result + status.hashCode();
        result = 29 * result + time.hashCode();
        return result;
    }

    public String toString() {
        StringBuilder text = new StringBuilder();
        text.append("{id: ");
        text.append(id);
        text.append(", at ");
        text.append(time);
        text.append(", writer: ");
        text.append(writerId);
        text.append(", message: ");
        text.append(message);
        text.append(", status: ");
        text.append(status);
        text.append("}");
        return text.toString();
    }
}
